/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package internetplus_test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

/**
 *
 * @author luobo
 */
public class ActivityTest {

    public static void main(String args[]) {
//        registerTest1();
//        registerTest2();
        loginTest1();
        //        loginTest2();
        try {

            addNewActivityTest();
        } catch (ParseException ex) {
            Logger.getLogger(ActivityTest.class.getName()).log(Level.SEVERE, null, ex);
        }
//        loadActivities();
//        loadUserInfoByAidTest();
//        participateInActivityTest();
//        searchActivitiesByKeywordTest();
//          collectActivityTest();

    }

    public static void collectActivityTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/activity/collectActivity";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/activity/collectActivity()";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("aid", "1");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }

    public static void loadActivities() {
        String httpUrl = "http://localhost:8080/InternetPlus/activity/loadActivities";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/activity/loadActivities";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("currentPageNum", "1");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }

    public static void searchActivitiesByKeywordTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/activity/searchActivitiesByKeyword";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/activity/searchActivitiesByKeyword";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("keyword", "校园");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);

    }

    public static void loadUserInfoByAidTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/activity/loadUserInfoByAid";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/activity/loadUserInfoByAid";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("aid", "1");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }

    public static void participateInActivityTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/activity/participateInActivity";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/activity/participateInActivity";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("aid", "1");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }

    public static void addNewActivityTest() throws ParseException {
        String httpUrl = "http://localhost:8080/InternetPlus/activity/addNewActivity";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/activity/addNewActivity";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("ActivityTitle", "校园运动会");
        jsonObject.put("queue", "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1");
        jsonObject.put("ActivityTotal", "123");
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
//        Date date = sdf.parse("2016-06-17");
        jsonObject.put("ActivityTime", "2016-06-17");
        jsonObject.put("ActivityAcademy", "所有学院");
        jsonObject.put("ActivityLocation", "老操场");
        jsonObject.put("ActivityContent", ".....");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }

    public static void registerTest1() {
        String httpUrl = "http://118.89.29.87:8080/InternetPlus/register";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "758172047@qq.com");
        jsonObject.put("password", "1234567890");
        jsonObject.put("sex", "男");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }

    public static void registerTest2() {
        String httpUrl = "http://118.89.29.87:8080/InternetPlus/register";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "1954627313@qq.com");
        jsonObject.put("password", "1234567890");
        jsonObject.put("sex", "男");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }

    /**
     *
     */
    public static void loginTest1() {
        String httpUrl = "http://localhost:8080/InternetPlus/authorization/login";
//        String httpUrl = "http://118.89.29.87:8080/InternetPlus/authorization/login";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "758172047@qq.com");
        jsonObject.put("password", "1234567890");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }

    /**
     *
     */
    public static void loginTest2() {
        String httpUrl = "http://118.89.29.87:8080/InternetPlus/login";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "1954627313@qq.com");
        jsonObject.put("password", "1234567890");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }
}
